Base Class |
|
A Base class generated by WS-AppServer contains information that is internally used by WS-AppServer for application execution. The Base class generated out of Standard class maps to the corresponding database table. Since this class is system generated, it should not be modified. It contains the following information:
- ClassInfo, which describes the class.
- Accessors and mutators (getandsetmethods) that act on the attributes.
If you want to customize the generated class and add your business logic, you may do so in the Extension class.
About Relationships Between Objects
An object may be involved in multiple relations. For example, a Product object might have relation not only to a Supplier object, but also to an Order, a Pricing Scheme, and so on. For each relation that the object has, a relation object is bound to the object. Such a relation object stores:
- Related object
- Required information (metadata) about the relation.
There are different types of relation objects - One-to-One (1:1), One-to-Many (1:N), and Many-to-One (N:1).
About Methods Involving Relationships
Relations are described in terms of Primary Key (PK) and Foreign Key (FK). Each Relation object has a RelationInfo object attached, which describes the relation. The Relation_FK object has a corresponding RelationInfo_FK object. The RelationInfo_FK object stores the following information:
- identifier - Unique identifier to identify the Relation and RelationInfo objects. Within a class, each relation must have a unique identifier.
- localisPK - Defines whether 'origin' side of the relation holds the PK.
- localAttributes - Defines the attributes that form the FK or PK.
- loadMethod - Method to be invoked to load the related objects. This method is a generated method.
- relatedClass - The name of the class at the 'target' side of the relation.
- relatedAttributes - The names of the attributes that form the PK or FK at the target side.
- relatedIdentifier - The identifier of the relation at the 'target' side.
The RelationInfo object has a method to create a Relation object (either SingleRelation_FK or MultiRelation_FK), based on its content. The RelationInfo_FK objects are stored with the ClassInfo object of a BusObject. The FK/PK model is the underlying model of relations used in WS-AppServer. Changing the FK changes the relation. Therefore, all methods that update the relation (setSupplier, addProduct, removeProduct) are translated into a call to update the FK field(s).
In the Base class of any object, code is generated to initialize the relation objects for each relation. The following code is generated per relation: - Relation identifier (public final static String)
- RelationInfo object, which is a static attribute.
- Relation object, including the generated RelationInfo object.
- Method to load the objects in the relation (e.g. loadSupplier()).
- The API of the relation (getSupplier, setSupplier, getProducts, addProduct, removeProduct).
All relation objects from an object are collected in a list. A detailed example of the generated code covering both 1:1 and 1:n relationship models is given below: For the Product-Supplier relationship, the following code shows the methods that are generated at the Product side, i.e. the 1-side of the relation (ProductsBase.java):public Suppliers getSupplierIDObject() { return (Suppliers)getSingleRelationObject(REL_SupplierIDObject); } public void setSupplierIDObject(Suppliers a_Suppliers) { if (a_Suppliers == null) { this.setNull("SupplierID"); } else { this.setSupplierID(a_Suppliers.getSupplierID()); } this.update(); } public Suppliers loadSupplierIDObject() { String queryText = "select * from Suppliers where SupplierID = :SupplierID"; QueryObject query = new QueryObject(queryText); query.addParameter("SupplierID", "Suppliers.SupplierID", QueryObject.PARAM_INT, new Integer(getSupplierID())); query.setResultClass(Suppliers.class); return (Suppliers)query.getObject(); }
public BusObjectIterator getProductsObjects() { return getMultiRelationObjects(REL_ProductsObjects); } public void addProductsObjects(Products a_Products) { a_Products.setSupplierID(this.getSupplierID()); a_Products.update(); } public void removeProductsObjects(Products a_Products) { a_Products.setNull("SupplierID"); a_Products.update(); } public BusObjectIterator loadProductsObjects() { String queryText = "select * from Products where SupplierID = :SupplierID"; QueryObject query = new QueryObject(queryText); query.addParameter("SupplierID", "Products.SupplierID", QueryObject.PARAM_INT, new Integer(getSupplierID())); query.setResultClass(Products.class); return query.getObjects(); }
In this manner, the Relationship methods can be used to add, remove, or set related objects.